/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package weka.attributeSelection.semiAS.semiClusterAS;

import weka.core.Instances;

/**
 *
 * @author Administrator
 */
public class RepartialLabledDistEval extends LabeledDistEval {

    public RepartialLabledDistEval(final Instances data) {
        super(data);
    }

    public double getDistance(int i, int j) {
        double r = 0.0;

        double rij = Correlate.correlate(i, j, m_labledInstances);
        double ric = Correlate.correlate(i, m_classIndex, m_labledInstances);
        double rjc = Correlate.correlate(j, m_classIndex, m_labledInstances);
        r = rij * Math.sqrt((1 - ric * ric) * (1 - rjc * rjc)) + ric * rjc;

        r = Math.abs(r);

        if (r > 1) {
            r = 1;
        }
        if (r < 0) {
            r = 0;
        }
        return 1 - r;
    }
}
